<template>
  <div class="my-search">
    <!-- header 页头-->
    <div class="title">
      <van-search
        v-model="value"
        show-action
        shape="round"
        background="#4fc08d"
        placeholder="进口榴莲 新鲜"
        @search="onSearch"
      >
        <template #action >
          <div @click="onSearch" style="color: white">搜索</div>
        </template>
      </van-search>
    </div>
    <!-- 内容区 -->
    <div class="content">
      <!-- 一楼 历史搜索 -->
      <div class="history-search" v-if="searchText.length!=0">
        <!--一楼 标题栏 -->
        <div>
          <van-nav-bar :border="false">
            <template #left>
              <van-icon name="fire-o" color="#ee0a24" size="1.5em" />
              <span id="span1">历史搜索</span>
            </template>
            <template #right>
              <van-icon
                name="delete-o"
                color="black"
                size="1.2em"
                @click="delsearch"
              />
            </template>
          </van-nav-bar>
        </div>
        <!-- 一楼 列表内容区 -->
        <div>
          <van-button
            v-for="(item, index) in searchText.slice(0,8)"
            :key="index"
            color="#857A7A"
            round
            plain
            type="info"
            size="small"
            style="margin: 3px 10px"
            ><span style="font-size: 12px; color: black">{{
              item
            }}</span></van-button
          >
          <van-button v-if="searchText.length>=8" @click="addlist" style="border: 0"
            ><van-icon name="arrow-down"
          /></van-button>
          <div v-if="list">
            <van-button
            v-for="(item, index) in searchText.slice(8)"
            :key="index"
            color="#857A7A"
            round
            plain
            type="info"
            size="small"
            style="margin: 3px 10px"
            ><span style="font-size: 12px; color: black">{{
              item
            }}</span></van-button
          >
          </div>
        </div>
      </div>
      <!-- 二楼 热门推荐 -->
      <div class="hot-search">
        <!--二楼 标题栏 -->
        <div>
          <van-nav-bar :border="false">
            <template #left>
              <van-icon name="fire-o" color="#ee0a24" size="1.5em" />
              <span id="span2">搜索推荐</span>
            </template>
          </van-nav-bar>
        </div>
        <!-- 二楼 列表内容区 -->
        <div class="search-list">
          <van-row type="flex">
            <van-col span="6" offset="2">
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
            </van-col>
            <van-col span="10" offset="4">
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
              <van-cell :border="false" value="进口榴莲" />
            </van-col>
          </van-row>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: "",
      searchText: [],
      list:false,
    };
  },
  methods: {
    // 标题的搜索点击事件
    onSearch() {
      if(this.value){
      // this.$router.push("/searchresult/" + this.value);
      this.searchText.unshift(this.value);    
      this.value=""  
      }     
    },
     // 历史搜索中的下拉点击
    addlist() {
      this.list=!this.list
    },
    // 历史搜索中的清空
    delsearch() {
      this.searchText=[]
    },
  },
};
</script>

<style scoped>
.my-search {
  background-color: #4fc08d;
}
.my-search .title {
  padding: 0.6rem 0.2rem;
  background-color: #4fc08d;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}
.my-search .content {
  border-radius: 1.25rem 1.25rem 0 0;
  background-color: white;
  padding: 0 0.625rem;
  margin-top: 4.5rem;
}
.my-search .content .history-search > div {
  padding: 0.8rem 0;
}
.my-search .content .history-search #span1 {
  padding-left: 0.1rem;
  font-size: 1.1rem;
  font-weight: 600;
}
.my-search .content .hot-search > div {
  padding: 0.8rem 0 0.5rem;
}
.my-search .content .hot-search #span2 {
  padding-left: 0.1rem;
  font-size: 1.1rem;
  font-weight: 600;
}
.my-search .content .hot-search .search-list {
  margin-top: -0.5rem;
}
.my-search .content .hot-search .search-list .van-cell--borderless {
  padding: 0.2rem 1rem;
}

.van-search__action:active{
  background-color: #4fc08d;
}
</style>
